#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2022/6/12 15:36
# @Author : Violet
# @File : config.py
# @desc : 配置文件
from typing import Union, List

from pydantic import BaseSettings, AnyHttpUrl


# ---------------------------------------------美观线-------------------------------------------------------

class Settings(BaseSettings):
    PROJECT_VERSION: Union[int, str] = 5.0  # 版本
    BASE_URL: AnyHttpUrl = "http://127.0.0.1:8000"  # 开发环境

    API_PREFIX: str = "/api"  # 接口前缀
    TEMPLATES_DIR: str = 'templates'  # 静态文件目录
    GLOBAL_ENCODING: str = 'utf-8'  # 全局编码
    CORS_ORIGINS: List[AnyHttpUrl] = ["http://101.43.79.137:8999","http://localhost:8999"]  # 跨域请求

    # Session
    SECRET_KEY = "session"
    SESSION_COOKIE = "session_id"
    SESSION_MAX_AGE = 14 * 24 * 60 * 60
    # Jwt
    JWT_SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
    JWT_ALGORITHM = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 24 * 60
    TOKEN_URL = "/111"

    # DATABASE_URI: str = "mysql+asyncmy://root:123456@localhost:3306/zyr_init?charset=utf8mb4"  # MySQL(异步)
    # DATABASE_URI: str = "mysql+pymysql://root:123456@localhost:3306/zyr_init?charset=utf8"
    DATABASE_ECHO: bool = False  # 是否打印数据库日志 (可看到创建表、表数据增删改查的信息)
    # REDIS_URI: str = "redis://:@localhost:6379/1"  # redis

    LOGGER_DIR: str = "logs"  # 日志文件夹名
    LOGGER_NAME: str = '{time:YYYY-MM-DD_HH-mm-ss}.log'  # 日志文件名 (时间格式)
    LOGGER_LEVEL: str = 'DEBUG'  # 日志等级: ['DEBUG' | 'INFO']
    LOGGER_ROTATION: str = "12:00"  # 日志分片: 按 时间段/文件大小 切分日志. 例如 ["500 MB" | "12:00" | "1 week"]
    LOGGER_RETENTION: str = "7 days"  # 日志保留的时间: 超出将删除最早的日志. 例如 ["1 days"]

    # 权限数据表 (格式务必为 {'名称', '描述'})
    PERMISSION_DATA: List[dict] = [{'admin': '管理员权限'}, {'teacher': '教师权限'}, {'student': '学生权限'}]

    class Config:
        case_sensitive = True  # 区分大小写


settings = Settings()
